package com.ydd.mapper;

import com.github.pagehelper.Page;
import com.ydd.dto.ArticlePageDTO;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ydd.entity.YddArticle;
import com.ydd.vo.YddArticleVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ArticleMapper extends BaseMapper<YddArticle> {

    /**
     * 获取文章总数
     *
     * @return
     */
    @Select("select COUNT(*) from ydd_article")
    Integer count();

    /**
     * 获取热点数据
     *
     * @return
     */
    @Select("select * from ydd_article order by  lovenum desc limit 10")
    YddArticle[] hotArticles();

    /**
     * 根据分类id获取文章数量
     *
     * @param id
     * @return
     */
    @Select("select COUNT(*) from ydd_article where cateid=#{id}")
    Integer countByCate(Long id);

    /**
     * 文章分页查询
     *
     * @param articlePageDTO
     * @return
     */
    Page<YddArticleVO> list(ArticlePageDTO articlePageDTO);

    /**
     * 根据id删除
     *
     * @param id
     */
    @Delete("DELETE FROM `ydd_article` WHERE `id` = #{id} ;")
    void deleteById(Integer id);

    /**
     * 添加文章
     * @param yddArticle
     */
    @Insert("INSERT INTO `ydd_article` VALUES(\n" +
            "null,#{title},#{author},#{keywords},\n" +
            "#{description},#{content},#{pic},#{click},\n" +
            "#{ishot},#{istop},#{createDate},#{updateDate},\n" +
            "#{cateid},#{tags},#{status},#{lovenum},\n" +
            "#{userId},#{defaultData});")
    void add(YddArticle yddArticle);

    /**
     * 文章详情
     * @param id
     * @return
     */
    @Select("select * from ydd_article where id = #{id}")
    YddArticle rowInfo(Integer id);

//    /**
//     * 文章修改
//     * @param yddArticle
//     */
//    void updateOne(YddArticle yddArticle);

    @Select("select id from ydd_article")
    Integer[] allId();
}
